@extends('admin.admin')

@section('content')

        <!-- Date Picker -->
<link rel="stylesheet" href="{{ asset("/components/AdminLTE/plugins/datepicker/datepicker3.css") }}">

<!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        账册
        <small>账册</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="/admin/account_books">账册</a></li>
        <li class="active">账册</li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">

            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">账册</h3>
                    <div class="box-tools">
                        {{--<a href="{{route('admin.goods.create')}}" type="button" class="btn btn-block btn-success btn-xs"><i class="icon  glyphicon glyphicon-plus"></i> 添加</a>--}}
                    </div>
                </div>

                <!-- /.box-body -->

                <div class="box-body form-inline">

                   <div class="form-group" style="margin-right: 15px;">
                        <label>比对次数:</label>
                        {!! Form::text('dcrTimes',@$dcrTimes,['class'=>'form-control','placeholder'=>'次数','id'=>'dcrTimes'])!!}

                    </div>
                    <div id="datepicker2" class="input-daterange input-group">
                        {{--<input type="text" class="input-sm form-control" name="start" />--}}
                        {!! Form::text('date',@$date,['class'=>'input-sm form-control','placeholder'=>'月份', 'id'=>'reservation'])!!}
                    </div>

                    <button type="submit" class="btn btn-primary" id="submit">提交</button>


                </div>

            </div>
            <!-- /.box box-primary -->

            <div class="box box-primary">
                <div class="box-body table-responsive no-padding">


                    <table class="table table-hover" id="station">
                        <tr>
                            <th style="width: 50px">商品id</th>
                            <th style="width: 50px">商品编号</th>
                            <th style="width: 50px">商品名称</th>
                            <th style="width: 50px">商品库存</th>
                            <th style="width: 50px">入库数量</th>
                            <th style="width: 50px">出库数量</th>
                            <th style="width: 50px">应剩余数量</th>
                            <th style="width: 50px">期初数量</th>
                            <th style="width: 50px;">实际剩余数量</th>
                            <th style="width: 50px">单位</th>
                            <th style="width: 50px">库位信息</th>
                        </tr>
                    </table>
                </div>
            </div>
            <!-- /.box box-primary -->

        </div>
    </div>


</section>
<!-- /.content -->
<!-- Select2 -->
<script type="text/javascript" src="{{ asset("/components/AdminLTE/plugins/select2/select2.full.min.js") }}"></script>

<script>

    $('#submit').click(function(e){
        var dataForm = {};
        var dcrTimes = $('#dcrTimes').val();            //次数
        var reservation = $('#reservation').val();      //时间，年月

        //dcrTimes = parseInt(dcrTimes);

        if(dcrTimes == "" || dcrTimes == undefined || dcrTimes == null ){
            alert('次数不能为空');
        }/*else if( typeof dcrTimes != 'number'){
            alert('次数必须为数字');
        }*/else if(reservation == "" || reservation == undefined || reservation == null){
            alert('月份不能为空');
        }else{
            dataForm.dcrTimes = dcrTimes;
            dataForm.date = reservation;

            urls = "/admin/account_books";

            $.ajax({
                type: "POST",
                url: urls,
                data: dataForm,
                dataType: "json",
                headers: {
                    'X-CSRF-Token': "{{csrf_token()}}"
                },
                async:true,
                cache:false,
                success: function (msg) {

                    $('.search-result').remove();
                    alert(msg.message);

                    console.log(msg);
                    if(msg.data){
                        $.each(msg.data, function(i, item){

                            //alert(i);
                            var html='',tds=[],indexEunm={
                                goods_id	:0,
                                goods_sn	:1,
                                goods_name	:2,
                                goods_number:3,
                                legalInQty	:4,
                                legalOutQty	:5,
                                legalRemainQty:6,
                                periodStartQty:7,
                                realRemainQty:8,
                                unitCiq:9,
                                storeInfo:10
                            };
                            html+='<tr class="search-result">';

                            $.each(item,function(j,val){
                                tds[indexEunm[j]]="<td>"+val+"</td>";

                                //alert( j + ':' + val );
                            });
                            html += tds.join("");
                            html +="</tr>";

                            $("#station").append($(html));
                        });

                    }//end if()

                }
            }); //end ajax
        }//end if()

    });
</script>
<script src="{{ asset("/components/AdminLTE/plugins/datepicker/bootstrap-datepicker.js")  }}"></script>
<script src="{{ asset("/components/AdminLTE/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js")  }}"></script>
<script>


    $('#datepicker2').find('input').datepicker( {
        format: "yyyy/mm",
        minViewMode: 1,
        autoclose: true,
        language: "zh-CN",
        keyboardNavigation: false,
        forceParse: false
    });



</script>

@endsection